package sort;

public class InsertionSort {

    public static void insertSort(int[] a, int length){
        for(int i = 1;i<length;++i){
            int value = a[i];
            int j = i-1;
            for(;j>=0;j--){
                if(a[j]>value){
                    a[j+1] = a[j];
                }else{
                    break;
                }
            }
            a[j+1] = value;
        }
    }

    public static void main(String[] args){
        int[] a = {80,20,100,50,3,45};
        insertSort(a,a.length);
        for(int i:a){
            System.out.printf("-"+i+"--");
        }
    }
}
